import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/componet/base_widget.dart';
import 'package:flutter_base/const/colors.dart';

///日期选择器

///显示底部弹框pop
Future<dynamic> showBottomSheets(
  ///返回的为啥是个字符串？？？
  BuildContext context,
  Widget widget,
) =>
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return widget;
        });

/// 带取消的单选
class AlertMultipleChoice extends StatelessWidget {
  const AlertMultipleChoice(this.list, {Key? key}) : super(key: key);

  final List<String> list;

  @override
  Widget build(BuildContext context) {
    final actions = list
        .map((text) => CupertinoActionSheetAction(
        child: DefaultText(text, color: CS.black70),
        onPressed: () => closePopup(text),
        isDefaultAction: true))
        .toList();
    actions.add(CupertinoActionSheetAction(
        child: const DefaultText('取消', color: CS.mainBlack),
        onPressed: () => closePopup(null),
        isDefaultAction: true));
    return CupertinoActionSheet(actions: actions);
  }
}
///  关闭弹窗
///  也可以通过 Navigator.of(context).pop()
void closePopup([dynamic value]) => pop(value);

/// 返回上一个页面
void pop<T extends Object>([dynamic result]) =>
    globalNavigatorKey.currentState?.pop<dynamic>(result);

GlobalKey<NavigatorState> globalNavigatorKey = GlobalKey();

///  showCupertinoModalPopup
///  关闭 closePopup()
///  全屏显示
// Future<T>? showCupertinoBottomPagePopup<T>(
//     {WidgetBuilder? builder,
//     Widget? widget,
//     bool useRootNavigator = false,
//     ImageFilter? filter}) {
//   assert(builder != null || widget != null);
//   return showCupertinoModalPopup(
//       context: globalNavigatorKey.currentContext,
//       builder: builder ?? (BuildContext context) => widget,
//       filter: filter,
//       useRootNavigator: useRootNavigator);
// }

///输入框弹框
Future<String> showInputDialog(
    BuildContext context, TextEditingController controller,
    {bool isPhone = false}) async {
  final data= await showCupertinoDialog(
      context: context,
      builder: (context) {
        return CupertinoAlertDialog(
            content: Card(
                elevation: 0.0,
                child: TextField(
                  controller: controller,
                  keyboardType:
                      isPhone ? TextInputType.number : TextInputType.text,
                  // maxLength: isPhone ? 11 : 20,
                  decoration: const InputDecoration(
                      contentPadding:
                          EdgeInsets.symmetric(vertical: 8, horizontal: 15),
                      border: InputBorder.none,
                      hintText: '   请输入',
                      hintStyle: TextStyle(fontSize: 14)),
                )),
            actions: [
              CupertinoDialogAction(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: const Text('取消'),
              ),
              CupertinoDialogAction(
                onPressed: () {
                  Navigator.pop(context,controller.text.trim());
                  //setState(() {});
                },
                child: const Text('确定'),
              )
            ]);
      });
    return data as String;
}
